# Display all shifts in the datastore 


import webapp2
from google.appengine.ext import db

import ext


class MainPage(ext.SlotHandler):
	def get(self):
		self.response.out.write(open('html/header-submitAvail.html','r').read())
		self.response.out.write("""
		<html>
		<head>
		<script language="JavaScript"> \n
		var myshifts = [""")
		for sh in ext.Shift.all():
			self.response.out.write("'%s_%s', " % (sh.day, sh.time-8))
		self.response.out.write('];')
		
		cal = ext.Calendar.get(db.Key(self.request.get('cal')))
#        try:
#            x = get('email')
#        except NameError:
#            x = None
#
#        # Test whether variable is defined to be None
#        if x is None:
#			
#        else:
#            self.response.out.write("var owner = '" + ext.Account.gql("WHERE email = :1", x).get() + "';")

		self.response.out.write("var calName = '" + cal.name + "';")	

		if cal.closed == False:
			self.response.out.write(open('html/userCalOpen.html','r').read())
		else:
			self.response.out.write(open('html/userCalClosed.html','r').read())
		self.response.out.write(open('html/footer-addUsers.html','r').read())
		
app = webapp2.WSGIApplication([('/userCal*', MainPage)], debug=True)